From: Jasper St. Pierre Date: Sun, 13 Feb 2011 16:43:32 +0000 (-0500) Subject: lookingGlass: use new history manager implementation X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~8950 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=4bedbca66fa485056b7f63e3ce94b326a610805e;p=gnome-shell.git lookingGlass: use new history manager implementation This starts saving lookingGlass history in gsettings, and also adds the ability to clear the text field by pressing 'down' on the last entry, like the run dialog and readline allow. https://bugzilla.gnome.org/show_bug.cgi?id=642237 --- diff --git a/data/org.gnome.shell.gschema.xml.in b/data/org.gnome.shell.gschema.xml.in index d45cba319..672642590 100644 --- a/data/org.gnome.shell.gschema.xml.in +++ b/data/org.gnome.shell.gschema.xml.in @@ -45,6 +45,10 @@ [] <_summary>History for command (Alt-F2) dialog + + [] + <_summary>History for the looking glass dialog + diff --git a/js/ui/lookingGlass.js b/js/ui/lookingGlass.js index 7e7805c69..c98fa22f7 100644 --- a/js/ui/lookingGlass.js +++ b/js/ui/lookingGlass.js @@ -14,6 +14,7 @@ const Mainloop = imports.mainloop; const Gettext = imports.gettext.domain('gnome-shell'); const _ = Gettext.gettext; +const History = imports.misc.history; const ExtensionSystem = imports.ui.extensionSystem; const Link = imports.ui.link; const Tweener = imports.ui.tweener; @@ -37,6 +38,8 @@ var commandHeader = 'const Clutter = imports.gi.Clutter; ' + 'const it = Main.lookingGlass.getIt(); ' + 'const r = Lang.bind(Main.lookingGlass, Main.lookingGlass.getResult); '; +const HISTORY_KEY = 'looking-glass-history'; + function Notebook() { this._init(); } @@ -671,18 +674,10 @@ function LookingGlass() { LookingGlass.prototype = { _init : function() { - this._idleHistorySaveId = 0; - let historyPath = global.userdatadir + '/lookingglass-history.txt'; - this._historyFile = Gio.file_new_for_path(historyPath); - this._savedText = null; - this._historyNavIndex = -1; - this._history = []; this._borderPaintTarget = null; this._borderPaintId = 0; this._borderDestroyId = 0; - this._readHistory(); - this._open = false; this._offset = 0; @@ -779,31 +774,23 @@ LookingGlass.prototype = { if (text == '') return true; this._evaluate(text); - this._historyNavIndex = -1; return true; })); + + this._history = new History.HistoryManager(HISTORY_KEY); + this._history.connect('changed', Lang.bind(this, function(history, text) { + this._entry.text = text; + })); + this._entry.clutter_text.connect('key-press-event', Lang.bind(this, function(o, e) { let symbol = e.get_key_symbol(); if (symbol == Clutter.Up) { - if (this._historyNavIndex >= this._history.length - 1) - return true; - this._historyNavIndex++; - if (this._historyNavIndex == 0) - this._savedText = this._entry.text; - this._entry.text = this._history[this._history.length - this._historyNavIndex - 1]; + this._history.prevItem(o.get_text()); return true; } else if (symbol == Clutter.Down) { - if (this._historyNavIndex <= 0) - return true; - this._historyNavIndex--; - if (this._historyNavIndex < 0) - this._entry.text = this._savedText; - else - this._entry.text = this._history[this._history.length - this._historyNavIndex - 1]; + this._history.nextItem(o.get_text()); return true; } else { - this._historyNavIndex = -1; - this._savedText = null; return false; } })); @@ -821,29 +808,6 @@ LookingGlass.prototype = { + 'font-family: "' + fontDesc.get_family() + '";'; }, - _readHistory: function () { - if (!this._historyFile.query_exists(null)) - return; - let [result, contents, length, etag] = this._historyFile.load_contents(null); - this._history = contents.split('\n').filter(function (e) { return e != ''; }); - }, - - _queueHistorySave: function() { - if (this._idleHistorySaveId > 0) - return; - this._idleHistorySaveId = Mainloop.timeout_add_seconds(5, Lang.bind(this, this._doSaveHistory)); - }, - - _doSaveHistory: function () { - this._idleHistorySaveId = false; - let output = this._historyFile.replace(null, true, Gio.FileCreateFlags.NONE, null); - let dataOut = new Gio.DataOutputStream({ base_stream: output }); - dataOut.put_string(this._history.join('\n'), null); - dataOut.put_string('\n', null); - dataOut.close(null); - return false; - }, - _pushResult: function(command, obj) { let index = this._results.length + this._offset; let result = new Result('>>> ' + command, obj, index); @@ -874,8 +838,7 @@ LookingGlass.prototype = { }, _evaluate : function(command) { - this._history.push(command); - this._queueHistorySave(); + this._history.addItem(command); let fullCmd = commandHeader + command; @@ -962,6 +925,7 @@ LookingGlass.prototype = { this.actor.show(); this.actor.lower(Main.chrome.actor); this._open = true; + this._history.lastItem(); Tweener.removeTweens(this.actor); @@ -979,7 +943,6 @@ LookingGlass.prototype = { this._objInspector.actor.hide(); - this._historyNavIndex = -1; this._open = false; Tweener.removeTweens(this.actor);